package com.my.xq.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;

import com.my.xq.domain.entity.CourtYwhSettings;
import com.sskj.core.repository.GenericRepository;

public interface CourtYwhSettingsRepository extends GenericRepository<CourtYwhSettings, String> {

	@Query(" SELECT t FROM CourtYwhSettings t where t.courtId = ?1 ORDER BY t.building asc, t.unit asc ")
	List<CourtYwhSettings> findAllByCourtId(String courtId);

	@Query(" SELECT t FROM CourtYwhSettings t where t.courtId = ?1 AND t.type = 'B' AND t.building = ?2 ")
	CourtYwhSettings findBuilding(String courtId, String building);

	@Query(" SELECT t FROM CourtYwhSettings t where t.courtId = ?1 AND t.type = 'U' AND t.building = ?2 AND t.unit = ?3 ")
	CourtYwhSettings findUnit(String courtId, String building, String unit);

	@Query(" SELECT t FROM CourtYwhSettings t WHERE t.courtId = ?1 AND t.type = 'B' ")
	List<CourtYwhSettings> findAllBuilding(String courtId);

	@Query(" SELECT t FROM CourtYwhSettings t WHERE t.courtId = ?1 AND t.type = 'U' AND t.building = ?2 ")
	List<CourtYwhSettings> findAllUnitOfBuilding(String courtId, String building);

	@Query(" SELECT t FROM CourtYwhSettings t WHERE t.courtId = ?1 AND t.type = 'U' ")
	List<CourtYwhSettings> findAllUnit(String courtId);

}
